package com.zxq.ai.domain.service;

import com.zxq.common.utils.DateUtil;
import com.zxq.common.utils.JsonUtil;
import com.zxq.ai.domain.exception.UserInvalidException;
import com.zxq.ai.domain.user.User;
import com.zxq.ai.domain.user.account.CashAccount;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class CashAccountDomain {

    /**
     * 生成实例
     */
    public CashAccount generateInstance(User user) {

        if (Objects.isNull(user) || Objects.isNull(user.getUserId())) {
            throw new UserInvalidException(String.format("用户[%s]信息不正确", JsonUtil.toJson(user)));
        }

        CashAccount cashAccount = CashAccount.builder()
                .accountId(user.getUserId())
                .userId(user.getUserId())
                .balanceAmount(0L)
                .frozenAmount(0L)
                .availableAmount(0L)
                .totalWithdrawAmount(0L)
                .totalRechargeAmount(0L)
                .createAt(DateUtil.millis())
                .updateAt(DateUtil.millis())
                .createBy("system")
                .createBy("system")
                .build();

        return cashAccount;
    }

    /**
     * 冻结资金
     * 【转账场景：第一步】把付款人的资金冻结
     * @param payerCashAccountA 付款人账户
     * @param payeeCashAccountB 收款人账户
     * @param amount
     * @param operator
     */
    public void frozen4Transfer(CashAccount payerCashAccountA, CashAccount payeeCashAccountB, Integer amount, Long operator) {

    }

    /**
     * 交割资金
     * 【转账场景：第二步】把付款人冻结的资金 转给收款人
     * @param payerCashAccountA 付款人账户
     * @param payeeCashAccountB 收款人账户
     * @param amount
     * @param operator
     */
    public void deliveryOfTransfer(CashAccount payerCashAccountA, CashAccount payeeCashAccountB, Integer amount, Long operator) {

    }
}
